#include<iostream>
#include<thread>
#include<unistd.h>
#include<vector>
using namespace std;

const int num = 4;
int ticketnum = 10000;

void ticket()
{
    while(1)
    {
        if(ticketnum>0)
        {
            //usleep(1000);

            //1抢票
            printf("get a ticket, id:%d\n", ticketnum--);
            //2模拟入库
            usleep(1000);
        }
        else{
            break;
        }
    }
}

int main()
{
    vector<thread> threads;
    for(int i = 0; i < num; i++)
    {
        threads.emplace_back(ticket);
    }
    for(auto& e : threads)
    {
        e.join();
    }
    return 0;
}